home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-23 | 5.6 KB | 213 lines |
- /*
- * QuickTime for Java SDK Sample Code
-
- Usage subject to restrictions in SDK License Agreement
- * Copyright: © 1996-1999 Apple Computer, Inc.
-
- */
-
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
-
- import quicktime.std.StdQTConstants;
- import quicktime.*;
- import quicktime.qd.*;
- import quicktime.io.*;
- import quicktime.std.image.*;
- import quicktime.std.movies.*;
- import quicktime.util.*;
-
- import quicktime.app.QTFactory;
- import quicktime.app.time.*;
- import quicktime.app.image.*;
- import quicktime.app.display.*;
- import quicktime.app.anim.*;
- import quicktime.app.players.*;
- import quicktime.app.spaces.*;
- import quicktime.app.actions.*;
-
-
- public class TransitionEffect extends Frame implements StdQTConstants, QDConstants {
-
- public static void main(String args[]) {
- try {
- QTSession.open();
-
- TransitionEffect te = new TransitionEffect("Transition Effect");
- te.show();
- te.toFront();
- } catch (Exception e) {
- e.printStackTrace();
- QTSession.close();
- }
-
- }
-
-
-
- TransitionEffect(String title) throws Exception {
- super (title);
-
- myQTCanvas = new QTCanvas(QTCanvas.kInitialSize, 0.5f, 0.5f);
- add("Center", myQTCanvas);
-
- Dimension d = new Dimension (300, 300);
-
- addNotify();
- Insets insets = getInsets();
- setSize ((insets.left + insets.right + d.width + 5), (insets.top + insets.bottom + d.height + 10));
-
- addWindowListener(new WindowAdapter() {
- public void windowClosing (WindowEvent e) {
- QTSession.close();
- dispose();
- }
-
- public void windowClosed (WindowEvent e) {
- System.exit(0);
- }
- });
-
- QDGraphics gw = new QDGraphics (new QDRect(d));
- comp = new Compositor (gw, QDColor.black, 20, 1);
-
- ImagePresenter idb = makeImagePresenter (new QTFile (QTFactory.findAbsolutePath ("pics/stars.jpg")),
- new QDRect(300, 220));
- idb.setLocation (0, 0);
- comp.addMember (idb, 2);
-
- ImagePresenter id = makeImagePresenter (new QTFile (QTFactory.findAbsolutePath ("pics/water.pct")),
- new QDRect(300, 80));
- id.setLocation (0, 220);
- comp.addMember (id, 4);
-
- CompositableEffect ce = new CompositableEffect ();
- AtomContainer effectSample = new AtomContainer();
- effectSample.insertChild (new Atom(kParentAtomIsContainer), kEffectWhatAtom, 1, 0, EndianOrder.flipNativeToBigEndian32(kWaterRippleCodecType));
- ce.setEffect (effectSample);
- ce.setDisplayBounds (new QDRect(0, 220, 300, 80));
- comp.addMember (ce, 3);
-
- Fader fader = new Fader();
- QTEffectPresenter efp = fader.getPresenter();
- efp.setGraphicsMode (new GraphicsMode (blend, QDColor.gray));
- efp.setLocation(80, 80);
- comp.addMember (efp, 1);
-
- comp.addController((Controller)new TransitionControl (20, 1, ef) );
-
- myQTCanvas.setClient (comp, true);
- comp.getTimer().setRate(1);
- }
-
-
- class Fader {
-
- int curr_frm = 0;
-
-
- Fader() throws Exception {
- File file = QTFactory.findAbsolutePath ("pics/Ship.pct");
- QTFile f = new QTFile (file.getAbsolutePath());
-
- QDGraphics g = new QDGraphics (new QDRect (78, 29));
- g.setBackColor (QDColor.black);
- g.eraseRect(null);
- ImagePresenter srcImage = ImagePresenter.fromGWorld(g);
- Compositable destImage = new GraphicsImporterDrawer (f);
-
- ef = new QTTransition ();
- ef.setRedrawing(true);
- ef.setSourceImage (srcImage);
- ef.setDestinationImage (destImage);
- ef.setDisplayBounds (new QDRect(78, 29));
- ef.setEffect (createFadeEffect (kEffectBlendMode, kCrossFadeTransitionType));
- ef.setFrames(60);
- ef.setCurrentFrame(0);
- }
-
-
- public QTEffectPresenter getPresenter() throws QTException {
- QTEffectPresenter efPresenter = new QTEffectPresenter (ef);
- return efPresenter;
- }
- }
-
-
-
- public AtomContainer createFadeEffect (int effectType, int effectNumber) throws QTException {
- AtomContainer effectSample = new AtomContainer();
- effectSample.insertChild (new Atom(kParentAtomIsContainer), kEffectWhatAtom, 1, 0, EndianOrder.flipNativeToBigEndian32(kCrossFadeTransitionType));
- effectSample.insertChild (new Atom(kParentAtomIsContainer), effectType, 1, 0, EndianOrder.flipNativeToBigEndian32(effectNumber));
- return effectSample;
- }
-
-
-
- private Compositor comp;
- private QTCanvas myQTCanvas;
- private QTTransition ef;
-
-
- private ImagePresenter makeImagePresenter (QTFile file, QDRect size) throws Exception {
- GraphicsImporterDrawer if1 = new GraphicsImporterDrawer (file);
- if1.setDisplayBounds (size);
- return ImagePresenter.fromGraphicsImporterDrawer (if1);
- }
- }
-
-
- class TransitionControl extends PeriodicAction implements TicklishController {
-
- TransitionControl (int scale, int period, QTTransition t) {
- super (scale , period);
- this.t = t;
- }
-
-
- QTTransition t;
- boolean waiting = false;
- int startWaitTime = 0;
- int waitForMsecs = 4000;
-
- public void addedToSpace (Space s) {}
-
- public void removedFromSpace () {}
-
- protected boolean constraintReached () {
- return false;
- }
-
- public void timeChanged (int tm) throws QTException {
- if (waiting)
- startWaitTime = tm;
- super.timeChanged(tm);
- }
-
- protected void doAction (float er, int tm) throws QTException {
- if (waiting) {
- if ((er > 0 && ((startWaitTime + waitForMsecs) <= tm))
- || (er < 0 && ((startWaitTime - waitForMsecs) >= tm))) {
-
- waiting = false;
- t.setRedrawing(true);
- } else
- return;
- }
- int curr_frm = t.getCurrentFrame();
- curr_frm++;
- t.setCurrentFrame(curr_frm);
- if (curr_frm > t.getFrames()) {
- curr_frm = 0;
- t.setRedrawing(false);
- t.setCurrentFrame(curr_frm);
- t.swapImages();
- waiting = true;
- startWaitTime = tm;
- }
- }
-
- }
-
-